import { registerAs } from '@nestjs/config';
import type { AppConfig } from './configuration.type';

export default registerAs('app', (): AppConfig => {
  return {
    nodeEnv: (process.env.NODE_ENV as AppConfig['nodeEnv']) || 'dev',
    port: parseInt(process.env.PORT || '3000', 10),
    jwtSecret: process.env.JWT_SECRET || 'secret',
    jwtExpiresIn: process.env.JWT_EXPIRES_IN || '60s',
    dbHost: process.env.DB_HOST || 'localhost',
    dbPort: parseInt(process.env.DB_PORT || '3306', 10),
    dbUser: process.env.DB_USER || 'root',
    dbPwd: process.env.DB_PWD || 'root',
    dbName: process.env.DB_NAME || 'nest_api',
    redisHost: process.env.REDIS_HOST || 'localhost',
    redisPort: parseInt(process.env.REDIS_PORT || '6379', 10),
    redisPassword: process.env.REDIS_PASSWORD || '',
    redisDb: parseInt(process.env.REDIS_DB || '0', 10),
    redisPrefix: process.env.REDIS_PREFIX || 'nest_api',
    redisTTL: parseInt(process.env.REDIS_TTL || '60', 10),
  };
});
